-- shape_change
-- create by dengc
-- 道具：  变身

return {
    apply = function(source, target, classId, value)
        local args = value;
        
        -- 参数配置错误
        if type(args) ~= "table" then
            return;
        end

        local shapeId = args["shape_id"];
        local propId = args["prop_id"];

        -- 查询变身信息
        local shapeInfo = ShapeChangeM.query(shapeId);

        -- 作用对象不是玩家自己
        if target.type ~= OBJECT_TYPE_USER then
            return;
        end

        -- 获取当前的出战宠物
        local pet = target:getActivePet();
        local userPetId = pet.classId;

        -- 不是当前出战的宠物
        local needId = shapeInfo["class_id"];
        if needId ~= userPetId then
            return;
        end

        -- 持续时间
        local condition = shapeInfo["condition"];

        local time = 0;
        if condition == "" or not condition["during_time"] then
            cclog("shape_chang.csv表的condition列未配置变身持续时间！");
            time = 999;
        else
            time = condition["during_time"];
        end

        -- 解析持续时间
        local duringType = ShapeChangeM.parseDuringCondition(time);

        if duringType == ShapeChangeM.DURING_FOREVER then
            -- 持续整个迷宫
            PropM.record(target, { propId, shapeId, 1, -1 }, "shape_change");
        elseif duringType == ShapeChangeM.DURING_FLOOR then
            -- 持续本层
            PropM.record(target, { propId, shapeId, 1, -1 }, "mixed");
        else
            -- 持续一定回合
            PropM.record(target, { propId, shapeId, 1, time }, "mixed");
        end

    end,
};
